/***************************************************************************************************/
/*!
 @header AudioFileWriter
 @abstract   ￼
 AudioFileWriter is a simple class encapsulating the functionality of two sets of APIs; QuickTime's
 Audio Extraction API's and Core Audio's Audio File APIs. It let's clients of this class perform
 audio extraction from a QTKit QTMovie object to AIFF files using a single method call.
 
 Note that this class uses the default extraction channel layout which is the aggregate
 channel layout of the movie (for example, all Rights mixed together, all Left Surrounds mixed together, etc).
 
 Because we're writing a file the stream description for the output is modified from the default
 (32-bit float, de-interleaved) to 16-bit, interleaved big endian. The sample rate will be set
 to the highest sample rate found in the movie.
 
 For more information regarding newer audio capabilities of QuickTime, please see the QuickTime 7 Update Guide:
 
 http://developer.apple.com/documentation/QuickTime/Conceptual/QT7UpdateGuide/Chapter01/Introduction.html
 
@discussion
 What is changed:
 <1> Due to automator execution, thread capability is limited to work with main thread.
 <2> Systems to report progress of extraction are removed.
 
 @discussion ￼
 Ported from AIFFWriter.m (Apple Software)
 Modified By: Hiroki Omae
 Original Author: QuickTime DTS
 
 Change History (most recent first): 
 
 <2> 03/24/06 must pass NSError objects to exportCompleted
 <1> 11/10/05 initial release
 
 � Copyright 2005-2006 Apple Computer, Inc. All rights reserved.
 
 @discussion
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */
/***************************************************************************************************/

//------------------------------------------------------------------------------------------------------------------------------------------------
// File Dependencies
//------------------------------------------------------------------------------------------------------------------------------------------------
#import <Cocoa/Cocoa.h>
#import <AudioToolbox/AudioToolbox.h>
#import <QTKit/QTKit.h>
#import <QuickTime/QuickTime.h>

//------------------------------------------------------------------------------------------------------------------------------------------------
// Type Definitions
//------------------------------------------------------------------------------------------------------------------------------------------------

/*!
 @class
 @abstract    Utility to export audio stream from QuickTime Movie
 @discussion  
 A single instance of this object can be used to extract audio
 from a QuickTime movie (via a QTKit Movie object) and will write
 an AIFF file preserving the audio layout from the Movie
 */
@interface AudioFileWriter : NSObject
{
@private
	NSString 					*mFileName;                     		// file name for the new .aiff file
	FSRef	  					mFileRef;                       		// file reference for this file
	FSRef	  					mParentRef;                     		// reference to parent directory of exporting file
	
	QTMovie					*mQTMovie;                      		// movie to extract audio from
	Float64					mMovieDuration;                 	// movie duration(in seconds)
	
	MovieAudioExtractionRef                         mAudioExtractionSession;        	// QT Audio Extraction Session Reference
	BOOL                                                         mExtractionComplete;            	// are we done yet?
	SInt64						mLocationInFile;                		// location to write new data
	SInt64						mSamplesRemaining;              	// how much more do we need to pull from the source?
	SInt64						mSamplesCompleated;             	// hom much have we done - used to drive progress UI
	SInt64						mTotalNumberOfSamples;          	// total number of samples to extract
	
	AudioStreamBasicDescription	           mSourceASBD;                    	// audio stream basic description of the source movie
	AudioStreamBasicDescription	           mOutputASBD;                    	// the asbd we're asking for
	AudioChannelLayout *		           mExtractionLayoutPtr;           	// the audio channel layout of the source
	UInt32                                                       mExtractionLayoutSize;          	// the size of the audio chanel layout
	AudioFileID					mExportFileID;                  		// file identifier for the new .aiff file
}

/*!
 @method     
 @abstract   Exports audio file from QTMovie
 @discussion
 main method call that will produce an AIFF file - it will try to
 export the movie on a separate thread but if it can't will schedule
 callbacks on the main thread 
 */
- (OSStatus)exportAudioFileFromMovie:(QTMovie *)inMovie toFile:(NSString *)inFullPath error:(NSError**)ppError;

@end

